package com.keepers.repair.service;

import com.alibaba.fastjson.JSONObject;
import com.keepers.repair.helper.SpHelper;
import com.keepers.repair.model.UserModel;
import com.keepers.repair.net.LogUtil;
import com.keepers.repair.utils.UtilsKt;

import java.nio.charset.Charset;

/**
 * auth aboom
 * date 2018/10/31
 */
public class MsgSender{

    private String code;

    public MsgSender(String message, String msgType) {
        UserModel userModel = SpHelper.getLoginUserInfo();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("Key", userModel.Gid);
        jsonObject.put("FromUserName", userModel.Name);
        jsonObject.put("FromGroupID", userModel.GroupGid);
        jsonObject.put("ToUserName", "All");
        jsonObject.put("Content", message);
        jsonObject.put("MType",msgType);
        jsonObject.put("MsgType", "Text");
        code = "$$" + UtilsKt.encodeBase64(jsonObject.toString()) + "\r\n";
        LogUtil.e("发送的json = " + jsonObject.toString());
    }

    public byte[] parse() {
        return code.getBytes(Charset.defaultCharset());
    }
}
